package me.wangqu.weiyouqu.web.rest.business.service;

import me.wangqu.weiyouqu.web.rest.business.dao.UserDao;
import me.wangqu.weiyouqu.web.rest.business.model.UserModel;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * 用户
 * Created by arcticfox on 6/22/16.
 */
@Service
public class CustomUserService {

    private final Logger log = LoggerFactory.getLogger(CustomUserService.class);

    @Autowired
    private UserDao userDao;


    /**
     * 创建 WEB 用户
     * @param model
     * @return
     */
    public boolean createUser(final UserModel model) {
        try {
            return userDao.createUser(model);
        } catch (Exception e) {
            log.error("WEB 用户创建失败", e.getMessage());
        }
        return false;
    }

    /**
     * 更新 WEB 用户密码
     * @param model
     * @return
     */
    public boolean changePassword(final UserModel model) {
        try {
            return userDao.changePassword(model);
        } catch (Exception e) {
            log.error("WEB 用户修改密码失败", e.getMessage());
        }
        return false;
    }

    /**
     * 根据 login 查询用户详情
     * @param login
     * @return
     */
    public UserModel findByLogin(final String login) {
        try {
            return userDao.findByLogin(login);
        } catch (Exception e) {
            log.error("WEB 用户查询详情失败", e.getMessage());
        }
        return null;
    }

}
